﻿dojo.addOnLoad(
  function () {

      AttachEvent();
      hideAllItemTemplate();
      dojo.query("*[id$='LblNomeLocaleSecco']")[0].style.display = "none"
  })

function ShowHide(evt) {
    var divElementName = evt.currentTarget.id.replace("ImageApri", "ItemTemplate")
    dojo.query("[id='" + divElementName + "']").forEach(function (tagElement) {
        if (tagElement.style.display == "none") {
            tagElement.style.display = ""
            evt.currentTarget.childNodes[1].src = "../../Styles/Images/Minus.png"

        }
        else {
            tagElement.style.display = "none"
            evt.currentTarget.childNodes[1].src = "../../Styles/Images/Plus.png"

        }
    })
}



function Redirect(evt) {

    var loc = dojo.query("*[id$='LblNomeLocaleSecco']")[0]
    loc = loc.innerHTML.replace(/ /gi, "_")
    var album
    if (evt.target.id.indexOf("ImgAddress") >= 0) {
        var Id = evt.target.id.replace("ImgAddress", "LblAlbum")
        album = dojo.byId(Id).innerHTML;
    }
    else {
        album = evt.target.innerHTML;
    }
    album = album.replace(/ /gi, "_")
    window.open("../Album-locale.aspx?Luogo=" + loc + "&Album=" + album)
}

function AttachEvent() {
    dojo.query("div[id*='ImageApri_']").forEach(function (tagElement) {
        dojo.connect(tagElement, "onclick", null, "ShowHide");
    });
    dojo.query("div[id*='ImgDiv']").forEach(function (tagElement) {
        dojo.connect(tagElement, "onclick", null, "Redirect");
    });
}

function hideAllItemTemplate() {

    dojo.query("[id*='ItemTemplate_']").forEach(function (tagElement) {
        tagElement.style.display = "none";
    });

}
